package com.briup.jz.service.impl;

import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


import com.briup.jz.bean.Order;
import com.briup.jz.bean.OrderExample;
import com.briup.jz.dao.OrderMapper;
import com.briup.jz.service.IOrderService;
import com.briup.jz.utils.CustomerException;

	
	
	@Service
	public class OrderServiceImpl implements IOrderService {

	@Autowired	
	private OrderMapper orderMapper;
		
	@Override
	public void saveOrUpdate(Order order) throws CustomerException {
			
		
			
			
			if(order.getId()!=null) {
				orderMapper.updateByPrimaryKey(order);
			} else {
				
				orderMapper.insert(order);
			}
		
		}

		@Override
		public List<Order> query(Long id) {
			OrderExample example = new OrderExample();
			if(id!=null){
				example.createCriteria().andIdEqualTo(id);
			}
			List<Order> list = orderMapper.selectByExample(example);
			return list;
		}

		@Override
		public void deleteById(long id) throws CustomerException {
			Order order =orderMapper.selectByPrimaryKey(id);
			if (order == null) {
				throw new CustomerException("要删除的分类信息不存在");
			}
		 orderMapper.deleteByPrimaryKey(id);
		}
		
//取消派单
		@Override
		public void cancelSendOrder(Long orderId) {
			// TODO Auto-generated method stub
			
			
		}

//确认订单
		@Override
		public void confirmOrder(Long orderId) {
			// TODO Auto-generated method stub
			
		}

//查询订单
		@Override
		public void findById(Long id) {
			// TODO Auto-generated method stub
			Order order=orderMapper.selectByPrimaryKey(id);
			
			
		}

//拒绝订单
		@Override
		public void rejectOrder(Long orderId) {
			// TODO Auto-generated method stub
			
		}
//派单
		@Override
		public void sendOrder(Long waiterId, Long orderId) {
			// TODO Auto-generated method stub
			
			
		}

//員工服務結束
		@Override
		public void serviceCompleteOrder(Long orderId) {
			// TODO Auto-generated method stub
			
		}

//接單
		@Override
		public void takeOrder(Long orderId) {
			// TODO Auto-generated method stub
			
		}
		
//提交訂單
		@Override
		public void submitOrder(Order order) {
			/*设置下单时间*/
			order.setOrderTime(new Date().getTime());
			order.setStatus("待派单");
			if (order.getId()==null) {
				orderMapper.insert(order);
			}else {
				orderMapper.updateByPrimaryKey(order);
			}
			
		}
		
		

}
